<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 分页类 扩展
 *
 * 文档: <http://codeigniter.org.cn/user_guide/general/creating_libraries.html>
 */
class MY_Pagination extends CI_Pagination {
    /**
     * 以下参数设置主要是为了结合 Bootstrap 的UI分页样式而做的调正
     */
    public $use_page_numbers     = true; //启用后显示的是当前页码
    public $num_links            = 3; //左右的数字
    public $first_link           = 'First'; //首页文字
    public $last_link            = 'Last'; //尾页文字
    public $page_query_string    = true; //启用查询字符串，而不是URI段
    public $query_string_segment = 'page'; //传递页数的查询字符串
    public $full_tag_open        = '<ul class="pagination">'; //封装标签开始
    public $full_tag_close       = '</ul>'; //封装标签结束
    public $first_tag_open       = '<li title="首页">';
    public $first_tag_close      = '</li>';
    public $last_tag_open        = '<li>';
    public $last_tag_close       = '</li>';
    public $prev_tag_open        = '<li title="上一页">';
    public $prev_tag_close       = '</li>';
    public $num_tag_open         = '<li>';
    public $num_tag_close        = '</li>';
    public $cur_tag_open         = '<li class="active"><a>';
    public $cur_tag_close        = '</a></li>';
    public $next_tag_open        = '<li title="下页">';
    public $next_tag_close       = '</li>';
    public $prev_link            = '&lt;'; //上一页文字
    public $next_link            = '&gt;'; //下一页文字

    public function __construct($params = array()) {
        parent::__construct($params);
        log_message('debug', 'MY_Pagination Class Initialized');
    }

    /**
     * 页码转sql
     *
     * @param int $page 页数
     * @param int $perpage 每页显示数
     * @return array <1.limit 2.offset>
     */
    public static function page_to_limit($page, $perpage = 10) {
        $page = intval($page);
        $limit = intval($perpage);
        $offset = max(($page - 1) * $limit, 0);
        return array($limit, $offset);
    }
}

/* End of file MY_Pagination.php */
/* Location: ./application/library/MY_Pagination.php */
